from threading import Timer

from sympy import false


class TimerTask:
    def __init__(self, interval, task):
        self.interval = interval
        self.task = task
        self.timer = None

    def start(self):
        self.timer = Timer(self.interval, self.run)
        self.timer.start()

    def run(self):
        self.task()
        self.start()  # 重新启动定时器以持续执行任务

    def stop(self):
        if self.timer is not None:
            self.timer.cancel()
            self.timer = None

def ToNumber(v):
    try:
        return float(v)
    except ValueError:
        try:
            return int(v)
        except ValueError:
            return  false